package design.patterns.creational.singleton.hungry;

/**
 * @author gjx
 * @version v1.0
 * @Description
 * @date 2019/4/1 10:32
 */

import design.patterns.creational.singleton.MyThread;

/**
 * 饿汉式 不能完成延迟加载
 */
public class HungrySingleton {
    private static HungrySingleton lazySingleton = new HungrySingleton();

    private HungrySingleton(){

    }

    public static HungrySingleton getInstance(){
        return lazySingleton;
    }
}


class Test {
    public static void main(String[] args) {
        //单线程安全
       /* LazySingleton instance = LazySingleton.getInstance();
        System.out.println(instance);

        LazySingleton instance2 = LazySingleton.getInstance();
        System.out.println(instance2);*/
        //多线程不安全
        int count = 800;
        for (int i = 0; i < count; i++) {
            MyThread t1 = new MyThread();
            t1.start();

        }
        System.out.println("main....");

    }
}
